<template>
	<view>
		<view class="wxtip" id="JweixinTip" v-if="isShare" @click="noShare()">
		    <image src="../../static/center/weixin-tip.png" style="width:60px;height:60px;position:fixed;top:5px;right:20px;" />
		    <view class="wxtip-txt">点击右上角<br/>选择分享好友</view>
		</view>
		<view class="flex" id="pinpais" style="margin-top:10px;">
			<view class="pinpai-box" v-for="(item,i) in allPinpai" :key="item.id">
				<view class="pinpai-head">
					<view class="pname" @click="goPinpaiDetail(item.ppId)">{{item.ppPingpai.name}}</view>
					<view style="display: flex;">
						<view @click="deletePP(item.ppId)"><img src="../../static/center/lajitong2.jpg" class="fenxiang" /></view>
						<view @click="share(item.ppId,item.ppPingpai.name,item.ppPingpai.logo)" style="padding-left: 6px;"><img src="../../static/center/fx.png" class="fenxiang" /></view>
					</view>
				</view>
				<view class="pinpai-body" @click="goPinpaiDetail(item.ppId)">
					<view class="tixian"><view><img src="../../static/center/tx.png" >可提现</view>
					<view class="tixianmoney">{{item.tixianMoney}}</view></view>
					<view class="tixian"><view><img src="../../static/center/tjr.png" >推荐人</view>
					<view class="tjr">{{item.tuijianren?item.tuijianren.usersName:''}}</view></view>
					<view class="tixian"><view><img src="../../static/center/td.png" >团队人数</view>
					<view class="renshu">{{item.teamNum}}</view></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allPinpai:[],	//我的所有品牌
				isShare:false,	//是否点击分享了
				ppid:'',		//点击分享的品牌ID
				ppLogo:'',		//点击分享的品牌图片
				ppName:'',		//点击分享的品牌名称
			}
		},
		//分享给好友
		onShareAppMessage() {
			return {
				title: '品牌共享：'+this.ppName,
				imageUrl:this.host+'/image/pingpaiLogo/'+this.ppLogo,
				path: 'pages_pinpai/pinpai/pinpaiDetail?ppid='+this.ppid+'&tjr='+uni.getStorageSync('usersId')+'&isShare=true',
			};
		},
		//分享到朋友圈
		onShareTimeline() {
			return {
				title: '品牌共享：'+this.ppName,
				imageUrl:this.host+'/image/pingpaiLogo/'+this.ppLogo,
				path: 'pages_pinpai/pinpai/pinpaiDetail?ppid='+this.ppid+'&tjr='+uni.getStorageSync('usersId')+'&isShare=true',
			};
		},
		onLoad() {
			this.getMyAllPinpai()
		},
		methods: {
			//判空
			isNull(str){
				return str==null || str=="" || str==undefined
			},
			//得到用户全部品牌
			getMyAllPinpai(){
				this.$http.get('/ppUserPingpai/searchUserPingpai',{
					userId:uni.getStorageSync('usersId')
				}).then(res => {
					console.log(res.data.data)
					this.allPinpai = res.data.data
					if(this.allPinpai.length > 0){
						this.ppid = this.allPinpai[0].ppId;
						this.ppName = this.allPinpai[0].ppPingpai.name;
						this.ppLogo = this.allPinpai[0].ppPingpai.logo;
					}else{
						uni.hideShareMenu({
							
						})
					}
				})
			},
			//删除品牌会员(还未成为正式品牌会员)
			deletePP(ppid){
				uni.showModal({
					title:'提示',
					content:'确认删除吗？',
					success:(res)=> {
						if(res.confirm){
							this.$http.get('/ppUserPingpai/userDeletePinpaiByPpId',{
								ppId:ppid,
								userId:uni.getStorageSync('usersId')
							}).then(res => {
								if(res.data.code==200){
									this.$u.toast("删除成功")
									for(let j=0;j<this.allPinpai.length;j++){
										if(this.allPinpai[j].ppId==ppid){
											this.allPinpai.splice(j,1);
										}
									}
								}else{
									this.$u.toast(res.data.msg)
								}
							})
						}else if(res.cancel){
							
						}
					}
				})
			},
			//分享
			share(ppid,ppName,ppLogo){
				console.log("品牌ID："+ppid+" 品牌名称："+ppName+" 品牌logo："+ppLogo)
				this.ppid = ppid;
				this.ppLogo = ppLogo;
				this.ppName = ppName;
				this.isShare = true
			},
			//不分享
			noShare(){
				this.isShare = false
			},
			//跳转品牌详情
			goPinpaiDetail(ppid){
				console.log("跳转品牌详情")
				uni.navigateTo({
					url:'../pinpai/pinpaiDetail?ppid='+ppid
				})
			}
		}
	}
</script>

<style>
	.pname{font-size: 17px;}
	.wxtip{background: rgba(0,0,0,0.8); text-align: center; position: fixed; left:0; top: 0; width: 100%; height: 100%; z-index: 998;}
	.wxtip-txt{margin-top: 107px; color: #fff; font-size: 20px; line-height: 1.5;}
	#pinpais{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		margin-bottom: 20px;
	}
	.pinpai-box{
		background-color: white;
		border: 1px dashed #ccc;
		padding: 10px;
		width: 48%;
		margin-bottom: 20px;
	}
	#myhuiyuan{
		/*background-color: #efeff4;*/
	}
	.pinpai-head,.tixian{
		display: flex;
		margin-bottom: 10px;
		justify-content: space-between;
	}
	.pinpai-head{
		border-bottom: 1px solid #ccc;
	}
	.pinpai-box img{
		width: 16px;
		height: 16px;
	}
	#pinpais::after{
		content: " ";
		width: 40%;
		height: 1px;
	}
	.tixian .tjr{
		width: 56%;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	.tixian .tjr,.tixian .tixianmoney,.tixian .renshu{
		color: #007cdb;
	}
	.tixian>view:nth-child(1){
		font-size: 12px;
		width: 64px;
	}
</style>
